# Kernel development ***Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.*** --- The Debian system includes the kernel header files required for kernel module development and provides the toolchain needed to compile kernel modules. Users can directly develop and build new kernel modules on the device. # Environment Preparation The Quectel Pi M2 kernel version is 6.1.118-rt36. The system provides the corresponding Linux Kernel Headers at the following path:/usr/src/linux-headers-6.1-rockchip Install the tools required to compile kernel modules: ```plaintext apt update apt install -y make gcc ``` Create the Hello World kernel module project directory: ```plaintext mkdir -p /home/pi/helloworld cd /home/pi/helloworld ``` ## helloworld.c File Contents of the helloworld.c file: ```cpp #include #include #include MODULE_LICENSE("GPL"); MODULE_AUTHOR("Quectel"); MODULE_DESCRIPTION("A simple Hello World kernel module"); MODULE_VERSION("0.1"); static int __init helloworld_init(void) { printk(KERN_INFO "Hello World!\n"); return 0; } static void __exit helloworld_exit(void) { printk(KERN_INFO "Goodbye!\n"); } module_init(helloworld_init); module_exit(helloworld_exit); ``` ## Makefile File Contents of the Makefile file: ```javascript obj-m := helloworld.o KERNELDIR ?= /usr/src/linux-headers-6.1-rockchip PWD := $(shell pwd) all: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: $(MAKE) -C $(KERNELDIR) M=$(PWD) clean ``` # Build Enter the project directory: ```plaintext cd /home/pi/helloworld ``` Run the build: ```plaintext make ``` After the build is complete, the following kernel module file is generated in the directory:helloworld.ko # Run and Test Load the module: insmod helloworld.ko Check the module: lsmod | grep helloworld Check the running log: dmesg | grep "Hello World" Unload the module: rmmod helloworld Check the unload log: dmesg | grep "Goodbye"